﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Castle.MicroKernel.Facilities;
using MusicStore.Silverlight.Infrastructure;
using Castle.Core;
using Castle.MicroKernel;

namespace Structura.Silverlight.Infrastructure.ViewModel
{
	public class ViewModelInitializationFacility : AbstractFacility
	{
		protected override void Init()
		{
			this.Kernel.ComponentCreated += new ComponentInstanceDelegate(Kernel_ComponentCreated);
		}

		void Kernel_ComponentCreated(ComponentModel model, object instance)
		{
			// we configure the ViewModel injecting the optinal dependency to the view
			IView view = instance as IView;
			if (view != null)
			{
				view.ViewModel.View = view;
			}
		}
	}
}
